$(function(){
		 $("#login").click(function(){
		       var $parent = $(this).parent();
			   $parent.find(".formtips").remove();
				 //验证用户名
				
				if($("#userName").val() == ""){
					    var errorMsg = '请输入用户名.';
	                    alert(errorMsg) ;
	                    return false ;
				} 
				 //验证密码 
				if( $("#userPassword").val() == ""){
	                    var errorMsg = '请输入密码.';
						alert(errorMsg) ;
						return false ;
				} 
				 
			    
			    var code = $("#veryCode").val();
			    var errorMsg ; 
			    $.ajax({
			            type: 'POST',
			            url: '../../ResultServlet',
			            data:"c="+code,
			            dataType: 'text',
						async: false,
					    success: function(data){ 			          
					          errorMsg = data ;
						      if(errorMsg != ""){
						         alert(errorMsg);   
						      }
		                }  
				});
			    if(errorMsg != ""){
			       return false ;
			    }
			   $.ajax({
			        type: "POST",
					url: "patientLoginValidation.do",
					data:"userName="+encodeURI(encodeURI($("#userName").val()))+"&userPassword="+encodeURI(encodeURI($("#userPassword").val())),
					dataType: 'text',
					async: false,
				    success: function(data){
							if((data=="loginFail")){	
							    errorMsg='登陆名或密码错误';																									
							    $("#result").html(errorMsg) ;
							 }else{
							    errorMsg = "" ;
							    $("#result").html(errorMsg) ;
							 }
					}
			    });
			    if(errorMsg != ""){
			       return false ;
			    }
			    return true ;
				
         });
 });
		

